package com.sk.weichat.bean.message;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.io.Serializable;

/**
 *
 * 群通知
 * create by swy 2019-09-17
 */
@DatabaseTable
public class GroupMessage extends XmppMessage implements  Cloneable,Serializable {
    private static final long serialVersionUID = -2352369003725583412L;

    public static final int STATUS_GM_10 = 10; //设置管理员
    public static final int STATUS_GM_11 = 11; //取消管理员
    public static final int STATUS_GM_12 = 12; //你退出群
    public static final int STATUS_GM_13 = 13; //你被踢出群
    public static final int STATUS_GM_14 = 14; //其他人退出群
    public static final int STATUS_GM_15 = 15; //其他人被踢出群
    public static final int STATUS_GM_16 = 16; //邀请进群
    public static final int STATUS_GM_17 = 17; //申请进群
    public static final int STATUS_GM_18 = 18; //转让群主给你
    public static final int STATUS_GM_19 = 19; //转让群主给他人
    public static final int STATUS_GM_20 = 20; //你的邀请被拒绝
    public static final int STATUS_GM_21 = 21; //你的申请被拒绝

    public GroupMessage() {
    }

    public GroupMessage(String jsonData) {
        parserJsonData(jsonData);
    }

    @DatabaseField(generatedId = true)
    private int _id;

    @DatabaseField(canBeNull = false)
    private String ownerId;

    @DatabaseField
    private String userId;//房间id,相当于Friend的userId

    @DatabaseField(canBeNull = false)
    private String fromUserId;

    @DatabaseField(canBeNull = false)
    private String toUserId;

    @DatabaseField
    private int state;//消息的状态（设置管理员、退群、转让群、申请、邀请等）

    /**
     * 消息状态
     * 0 未处理 1 同意 2 拒绝 3过期 4已加入 5 失效 6超员
     */
    @DatabaseField
    private int msgState;

    @DatabaseField
    private int isGroup;//是否在群 0在群 ，1不在群里

    @DatabaseField
    private int role;

    @DatabaseField
    private String roomId;

    @DatabaseField
    private String objectId;

    @DatabaseField
    private String roomName;

    @DatabaseField
    private String nickName;

    @DatabaseField
    private String remarkName;

    @DatabaseField
    private String fromUserName;

    @DatabaseField
    private String toUserName;

    @DatabaseField
    private String handler;//处理人

    @DatabaseField
    private String handlerId;//处理人Id

    @DatabaseField
    private String reason;

    @DatabaseField
    private String opinion;

    @DatabaseField
    private String content;

    @DatabaseField
    private boolean isRead;

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public int get_id() {
        return _id;
    }

    public void set_id(int _id) {
        this._id = _id;
    }

    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getFromUserId() {
        return fromUserId;
    }

    public void setFromUserId(String fromUserId) {
        this.fromUserId = fromUserId;
    }

    public String getToUserId() {
        return toUserId;
    }

    public void setToUserId(String toUserId) {
        this.toUserId = toUserId;
    }

    public int getState() {
        return state;
    }

    public int getIsGroup() {
        return isGroup;
    }

    public void setIsGroup(int isGroup) {
        this.isGroup = isGroup;
    }

    public void setState(int state) {
        this.state = state;
    }

    public int getMsgState() {
        return msgState;
    }

    public void setMsgState(int msgState) {
        this.msgState = msgState;
    }

    public int getRole() {
        return role;
    }

    public void setRole(int role) {
        this.role = role;
    }

    public String getRoomId() {
        return roomId;
    }

    public void setRoomId(String roomId) {
        this.roomId = roomId;
    }

    public String getObjectId() {
        return objectId;
    }

    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }

    public String getRoomName() {
        return roomName;
    }

    public void setRoomName(String roomName) {
        this.roomName = roomName;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getRemarkName() {
        return remarkName;
    }

    public void setRemarkName(String remarkName) {
        this.remarkName = remarkName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getHandler() {
        return handler;
    }

    public void setHandler(String handler) {
        this.handler = handler;
    }

    public String getHandlerId() {
        return handlerId;
    }

    public void setHandlerId(String handlerId) {
        this.handlerId = handlerId;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getOpinion() {
        return opinion;
    }

    public void setOpinion(String opinion) {
        this.opinion = opinion;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public boolean isRead() {
        return isRead;
    }

    public void setRead(boolean read) {
        isRead = read;
    }

    @Override
    public String toString() {
        return "GroupMessage{" +
                "_id=" + _id +
                ", ownerId='" + ownerId + '\'' +
                ", userId='" + userId + '\'' +
                ", fromUserId='" + fromUserId + '\'' +
                ", toUserId='" + toUserId + '\'' +
                ", state=" + state +
                ", msgState=" + msgState +
                ", role=" + role +
                ", isGroup=" + isGroup +
                ", roomId='" + roomId + '\'' +
                ", objectId='" + objectId + '\'' +
                ", roomName='" + roomName + '\'' +
                ", nickName='" + nickName + '\'' +
                ", remarkName='" + remarkName + '\'' +
                ", fromUserName='" + fromUserName + '\'' +
                ", toUserName='" + toUserName + '\'' +
                ", handler='" + handler + '\'' +
                ", handlerId='" + handlerId + '\'' +
                ", reason='" + reason + '\'' +
                ", opinion='" + opinion + '\'' +
                ", content='" + content + '\'' +
                ", isRead=" + isRead +
                ", packetId='" + packetId + '\'' +
                ", type=" + type +
                ", timeSend=" + timeSend +
                ", isMySend=" + isMySend +
                '}';
    }

    /**
     * 解析接收到的消息
     *
     * @param jsonData
     */
    private void parserJsonData(String jsonData) {
        try {
            JSONObject jObject = JSON.parseObject(jsonData);
            type = getIntValueFromJSONObject(jObject, "type");
            timeSend = getDoubleFromJSONObject(jObject, "timeSend");
            fromUserId = getStringValueFromJSONObject(jObject, "fromUserId");
            toUserId = getStringValueFromJSONObject(jObject, "toUserId");
            roomName = getStringValueFromJSONObject(jObject, "roomName");
            fromUserName = getStringValueFromJSONObject(jObject, "fromUserName");
            toUserName = getStringValueFromJSONObject(jObject, "toUserName");
            content = getStringValueFromJSONObject(jObject, "content");
            objectId = getStringValueFromJSONObject(jObject, "objectId");
            userId = getStringValueFromJSONObject(jObject, "roomJid");
            roomId = getStringValueFromJSONObject(jObject, "roomId");
            packetId = getStringValueFromJSONObject(jObject, "messageId");
            isMySend = false;
            isRead=false;

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
